package com.lyf.scm.plan.api.controller;


import com.lyf.scm.plan.api.dto.EsAggregationDTO;
import com.lyf.scm.plan.api.dto.EsQueryDTO;
import com.lyf.scm.plan.api.dto.*;
import com.lyf.scm.plan.domain.service.SalesPlanEsService;
import com.lyf.scm.plan.insfrastructure.db.dataobject.es.SalesPlanEsEntity;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.util.controller.RomeController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 *
 * @author: haodong
 * @data: 2020/11/5 20:22
 */
@Slf4j
@RomeController
@RequestMapping("/api/v1/salesPlanES")
public class SalesPlanEsController {

    @Resource
    private SalesPlanEsService salesPlanEsService;

    /**
     * 动态分组查询
     *
     * @param esAggregation 查询参数
     * @return
     */
    @PostMapping("/queryByGroup")
    public Response queryByGroup(@RequestBody EsAggregationDTO esAggregation) {
        return Response.builderSuccess(salesPlanEsService.queryByGroup(esAggregation));
    }

    /**
     * 分页查询
     *
     * @param esQuery  查询参数
     * @param pageNum  当前页
     * @param pageSize 每页个数
     * @return
     */
    @PostMapping("/listPageQuery")
    public Response listPageQuery(@RequestBody EsQueryDTO esQuery,
                                  @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        return Response.builderSuccess(salesPlanEsService.listPageQuery(esQuery, pageNum, pageSize));
    }

    /**
     * 更新/新增
     *
     * @param indexQueryList 更新参数集合
     * @return
     */
    @PostMapping("/update")
    public Response update(@RequestBody List<SalesPlanEsEntity> indexQueryList) {
        return Response.builderSuccess(salesPlanEsService.update(indexQueryList));
    }

    /**
     * 动态导出
     *
     * @param esExportAggregationDTO 查询参数
     * @return
     */
    @PostMapping("/exportByGroup")
    public Response<EsScrollReturnDTO> exportByGroup(@RequestBody EsExportAggregationDTO esExportAggregationDTO) {
        return Response.builderSuccess(salesPlanEsService.exportByGroup(esExportAggregationDTO));
    }
}
